| Conditions | 1 |
| Paths | 1 |
| Total Lines | 94 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import L from 'leaflet'; |
||
| 13 | describe('utils', () => { |
||
| 14 | describe('stateFlagTimeout', () => { |
||
| 15 | it('sets state and initializes timeout with provided delay', () => { |
||
| 16 | const setTimeout = jest.fn((callback) => callback()); |
||
| 17 | const setState = jest.fn(); |
||
| 18 | const stateFlagTimeout = stateFlagTimeoutFactory(setTimeout); |
||
| 19 | const delay = 5000; |
||
| 20 | |||
| 21 | stateFlagTimeout(setState, 'foo', false, delay); |
||
| 22 | |||
| 23 | expect(setState).toHaveBeenCalledTimes(2); |
||
| 24 | expect(setState).toHaveBeenNthCalledWith(1, { foo: false }); |
||
| 25 | expect(setState).toHaveBeenNthCalledWith(2, { foo: true }); |
||
| 26 | expect(setTimeout).toHaveBeenCalledTimes(1); |
||
| 27 | expect(setTimeout).toHaveBeenCalledWith(expect.anything(), delay); |
||
| 28 | }); |
||
| 29 | }); |
||
| 30 | |||
| 31 | describe('determineOrderDir', () => { |
||
| 32 | it('returns ASC when current order field and selected field are different', () => { |
||
| 33 | expect(determineOrderDir('foo', 'bar')).toEqual('ASC'); |
||
| 34 | expect(determineOrderDir('bar', 'foo')).toEqual('ASC'); |
||
| 35 | }); |
||
| 36 | |||
| 37 | it('returns ASC when no current order dir is provided', () => { |
||
| 38 | expect(determineOrderDir('foo', 'foo')).toEqual('ASC'); |
||
| 39 | expect(determineOrderDir('bar', 'bar')).toEqual('ASC'); |
||
| 40 | }); |
||
| 41 | |||
| 42 | it('returns DESC when current order field and selected field are equal and current order dir is ASC', () => { |
||
| 43 | expect(determineOrderDir('foo', 'foo', 'ASC')).toEqual('DESC'); |
||
| 44 | expect(determineOrderDir('bar', 'bar', 'ASC')).toEqual('DESC'); |
||
| 45 | }); |
||
| 46 | |||
| 47 | it('returns undefined when current order field and selected field are equal and current order dir is DESC', () => { |
||
| 48 | expect(determineOrderDir('foo', 'foo', 'DESC')).toBeUndefined(); |
||
| 49 | expect(determineOrderDir('bar', 'bar', 'DESC')).toBeUndefined(); |
||
| 50 | }); |
||
| 51 | }); |
||
| 52 | |||
| 53 | describe('fixLeafletIcons', () => { |
||
| 54 | it('updates icons used by leaflet', () => { |
||
| 55 | fixLeafletIcons(); |
||
| 56 | |||
| 57 | const { iconRetinaUrl, iconUrl, shadowUrl } = L.Icon.Default.prototype.options; |
||
| 58 | |||
| 59 | expect(iconRetinaUrl).toEqual(marker2x); |
||
| 60 | expect(iconUrl).toEqual(marker); |
||
| 61 | expect(shadowUrl).toEqual(markerShadow); |
||
| 62 | }); |
||
| 63 | }); |
||
| 64 | |||
| 65 | describe('rangeOf', () => { |
||
| 66 | const func = (i) => `result_${i}`; |
||
| 67 | const size = 5; |
||
| 68 | |||
| 69 | it('builds a range of specified size invike provided function', () => { |
||
| 70 | expect(rangeOf(size, func)).toEqual([ |
||
| 71 | 'result_1', |
||
| 72 | 'result_2', |
||
| 73 | 'result_3', |
||
| 74 | 'result_4', |
||
| 75 | 'result_5', |
||
| 76 | ]); |
||
| 77 | }); |
||
| 78 | |||
| 79 | it('builds a range starting at provided pos', () => { |
||
| 80 | const startAt = 3; |
||
| 81 | |||
| 82 | expect(rangeOf(size, func, startAt)).toEqual([ |
||
| 83 | 'result_3', |
||
| 84 | 'result_4', |
||
| 85 | 'result_5', |
||
| 86 | ]); |
||
| 87 | }); |
||
| 88 | }); |
||
| 89 | |||
| 90 | describe('roundTen', () => { |
||
| 91 | it('rounds provided number to the next multiple of ten', () => { |
||
| 92 | const expectationsPairs = [ |
||
| 93 | [ 10, 10 ], |
||
| 94 | [ 12, 20 ], |
||
| 95 | [ 158, 160 ], |
||
| 96 | [ 5, 10 ], |
||
| 97 | [ -42, -40 ], |
||
| 98 | ]; |
||
| 99 | |||
| 100 | expect.assertions(expectationsPairs.length); |
||
| 101 | expectationsPairs.forEach(([ number, expected ]) => { |
||
| 102 | expect(roundTen(number)).toEqual(expected); |
||
| 103 | }); |
||
| 104 | }); |
||
| 105 | }); |
||
| 106 | }); |
||
| 107 |